﻿using GraphDrawing2.Canvas;
using GraphDrawing2.Core;
using GraphDrawing2.V2.Graph.Model;

namespace GraphDrawing2.V2.Concrete.Renderers
{
    public class ShapeRenderer : IShapeRenderer
    {
        public Appearance Default { get; private set; }
        public Appearance Hovered { get; private set; }
        public Appearance Selected { get; private set; }

        public ShapeRenderer()
        {
            Default = new Appearance();
            Hovered = new Appearance();
            Selected = new Appearance();
        }

        public void Render(DrawingContext dc, ShapeModel shape)
        {
            var g = dc.graphics;
            var state = g.Save();
            try
            {
//                g.TranslateTransform(shape.Position.X, shape.Position.Y);
//                var appearance = GetAppearance(shape.Hints);
//                using (var brush = appearance.CreateBrush())
//                    g.FillPath(brush, shape.Interior);
//                using (var pen = appearance.Border.CreatePen())
//                    g.DrawPath(pen, shape.Interior);
            }
            finally
            {
                g.Restore(state);
            }
        }

        Appearance GetAppearance(StateHints hint)
        {
            if (hint.HasFlag(StateHints.HOVERED))
                return Hovered;
            if (hint.HasFlag(StateHints.SELECTED))
                return Selected;
            return Default;
        }
    }
}